{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import os\n",
    "import json\n",
    "from pprint import pprint\n",
    "\n",
    "from datasets import load_dataset\n",
    "import pandas as pd\n",
    "from dotenv import load_dotenv\n",
    "from langchain_openai import ChatOpenAI\n",
    "\n",
    "import promptquality as pq\n",
    "from tqdm import tqdm\n",
    "tqdm.pandas()\n",
    "\n",
    "load_dotenv(\"../.env\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>query</th>\n",
       "      <th>id</th>\n",
       "      <th>answers</th>\n",
       "      <th>tools</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Where can I find live giveaways for beta acces...</td>\n",
       "      <td>0</td>\n",
       "      <td>[{\"name\": \"live_giveaways_by_type\", \"arguments...</td>\n",
       "      <td>[{\"name\": \"live_giveaways_by_type\", \"descripti...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>I need to understand the details of the Ethere...</td>\n",
       "      <td>1</td>\n",
       "      <td>[{\"name\": \"web_chain_details\", \"arguments\": {\"...</td>\n",
       "      <td>[{\"name\": \"peers\", \"description\": \"Retrieves a...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>What is the T3MA for 'ETH/BTC' using a 1h inte...</td>\n",
       "      <td>2</td>\n",
       "      <td>[{\"name\": \"t3ma\", \"arguments\": {\"symbol\": \"ETH...</td>\n",
       "      <td>[{\"name\": \"t3ma\", \"description\": \"Fetches the ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>List titles originally aired on networks '1' a...</td>\n",
       "      <td>3</td>\n",
       "      <td>[{\"name\": \"list_titles\", \"arguments\": {\"networ...</td>\n",
       "      <td>[{\"name\": \"get_animes\", \"description\": \"Retrie...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Fetch the competitor standings for the recentl...</td>\n",
       "      <td>4</td>\n",
       "      <td>[{\"name\": \"stagecompetitorstandings\", \"argumen...</td>\n",
       "      <td>[{\"name\": \"stagecompetitorstandings\", \"descrip...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                               query  id  \\\n",
       "0  Where can I find live giveaways for beta acces...   0   \n",
       "1  I need to understand the details of the Ethere...   1   \n",
       "2  What is the T3MA for 'ETH/BTC' using a 1h inte...   2   \n",
       "3  List titles originally aired on networks '1' a...   3   \n",
       "4  Fetch the competitor standings for the recentl...   4   \n",
       "\n",
       "                                             answers  \\\n",
       "0  [{\"name\": \"live_giveaways_by_type\", \"arguments...   \n",
       "1  [{\"name\": \"web_chain_details\", \"arguments\": {\"...   \n",
       "2  [{\"name\": \"t3ma\", \"arguments\": {\"symbol\": \"ETH...   \n",
       "3  [{\"name\": \"list_titles\", \"arguments\": {\"networ...   \n",
       "4  [{\"name\": \"stagecompetitorstandings\", \"argumen...   \n",
       "\n",
       "                                               tools  \n",
       "0  [{\"name\": \"live_giveaways_by_type\", \"descripti...  \n",
       "1  [{\"name\": \"peers\", \"description\": \"Retrieves a...  \n",
       "2  [{\"name\": \"t3ma\", \"description\": \"Fetches the ...  \n",
       "3  [{\"name\": \"get_animes\", \"description\": \"Retrie...  \n",
       "4  [{\"name\": \"stagecompetitorstandings\", \"descrip...  "
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = load_dataset(\"Salesforce/xlam-function-calling-60k\", split=\"train\").to_pandas()\n",
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>query</th>\n",
       "      <th>id</th>\n",
       "      <th>answers</th>\n",
       "      <th>tools</th>\n",
       "      <th>n_tools</th>\n",
       "      <th>len_query</th>\n",
       "      <th>n_function_calls</th>\n",
       "      <th>n_turns</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Where can I find live giveaways for beta acces...</td>\n",
       "      <td>0</td>\n",
       "      <td>[{'name': 'live_giveaways_by_type', 'arguments...</td>\n",
       "      <td>[{'name': 'live_giveaways_by_type', 'descripti...</td>\n",
       "      <td>1</td>\n",
       "      <td>58</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>I need to understand the details of the Ethere...</td>\n",
       "      <td>1</td>\n",
       "      <td>[{'name': 'web_chain_details', 'arguments': {'...</td>\n",
       "      <td>[{'name': 'peers', 'description': 'Retrieves a...</td>\n",
       "      <td>2</td>\n",
       "      <td>132</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>What is the T3MA for 'ETH/BTC' using a 1h inte...</td>\n",
       "      <td>2</td>\n",
       "      <td>[{'name': 't3ma', 'arguments': {'symbol': 'ETH...</td>\n",
       "      <td>[{'name': 't3ma', 'description': 'Fetches the ...</td>\n",
       "      <td>2</td>\n",
       "      <td>75</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>List titles originally aired on networks '1' a...</td>\n",
       "      <td>3</td>\n",
       "      <td>[{'name': 'list_titles', 'arguments': {'networ...</td>\n",
       "      <td>[{'name': 'get_animes', 'description': 'Retrie...</td>\n",
       "      <td>2</td>\n",
       "      <td>118</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Fetch the competitor standings for the recentl...</td>\n",
       "      <td>4</td>\n",
       "      <td>[{'name': 'stagecompetitorstandings', 'argumen...</td>\n",
       "      <td>[{'name': 'stagecompetitorstandings', 'descrip...</td>\n",
       "      <td>1</td>\n",
       "      <td>70</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                               query  id  \\\n",
       "0  Where can I find live giveaways for beta acces...   0   \n",
       "1  I need to understand the details of the Ethere...   1   \n",
       "2  What is the T3MA for 'ETH/BTC' using a 1h inte...   2   \n",
       "3  List titles originally aired on networks '1' a...   3   \n",
       "4  Fetch the competitor standings for the recentl...   4   \n",
       "\n",
       "                                             answers  \\\n",
       "0  [{'name': 'live_giveaways_by_type', 'arguments...   \n",
       "1  [{'name': 'web_chain_details', 'arguments': {'...   \n",
       "2  [{'name': 't3ma', 'arguments': {'symbol': 'ETH...   \n",
       "3  [{'name': 'list_titles', 'arguments': {'networ...   \n",
       "4  [{'name': 'stagecompetitorstandings', 'argumen...   \n",
       "\n",
       "                                               tools  n_tools  len_query  \\\n",
       "0  [{'name': 'live_giveaways_by_type', 'descripti...        1         58   \n",
       "1  [{'name': 'peers', 'description': 'Retrieves a...        2        132   \n",
       "2  [{'name': 't3ma', 'description': 'Fetches the ...        2         75   \n",
       "3  [{'name': 'get_animes', 'description': 'Retrie...        2        118   \n",
       "4  [{'name': 'stagecompetitorstandings', 'descrip...        1         70   \n",
       "\n",
       "   n_function_calls  n_turns  \n",
       "0                 2        1  \n",
       "1                 1        1  \n",
       "2                 1        1  \n",
       "3                 1        1  \n",
       "4                 1        1  "
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[\"tools\"] = df[\"tools\"].apply(json.loads)\n",
    "df[\"answers\"] = df[\"answers\"].apply(json.loads)\n",
    "df[\"n_tools\"] = df.tools.apply(lambda x: len(x))\n",
    "df[\"len_query\"] = df[\"query\"].apply(lambda x: len(x))\n",
    "df[\"n_function_calls\"] = df[\"answers\"].apply(lambda x: len(x))\n",
    "df[\"n_turns\"] = 1\n",
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "n_function_calls\n",
       "1     28461\n",
       "2     25422\n",
       "3      4697\n",
       "4      1056\n",
       "5       187\n",
       "6        94\n",
       "7        20\n",
       "10       19\n",
       "9        12\n",
       "8        12\n",
       "12        6\n",
       "11        4\n",
       "14        2\n",
       "20        2\n",
       "30        1\n",
       "23        1\n",
       "52        1\n",
       "26        1\n",
       "19        1\n",
       "24        1\n",
       "Name: count, dtype: int64"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.n_function_calls.value_counts()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "n_tools\n",
       "1    15410\n",
       "4    13078\n",
       "2    12726\n",
       "3    12655\n",
       "5     2427\n",
       "6     1464\n",
       "8     1132\n",
       "7     1108\n",
       "Name: count, dtype: int64"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.n_tools.value_counts()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Axes: ylabel='Frequency'>"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAk0AAAGdCAYAAAAPLEfqAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8hTgPZAAAACXBIWXMAAA9hAAAPYQGoP6dpAAA2SklEQVR4nO3de3RU5b3/8c+EkAvITLiYhCkBcpRyKVRuGqJgDyWHIKkVoa1AFNQUqk2Um0AowsF6CYYDFaqS0mOBLkGQ8xOqoMEYLvESA0QiFyFgBQLCJLYhGYgSQrJ/f3CyD2OobsKEmYT3a629lrOf7+z5Ps+SzGft2bPHZhiGIQAAAHynAF83AAAA0BgQmgAAACwgNAEAAFhAaAIAALCA0AQAAGABoQkAAMACQhMAAIAFhCYAAAALAn3dQFNRU1OjkydPqlWrVrLZbL5uBwAAWGAYhs6cOSOn06mAgO8+l0Ro8pKTJ08qKirK120AAIB6OH78uDp06PCdNYQmL2nVqpWki4tut9t93A0AALDC7XYrKirKfB//LoQmL6n9SM5utxOaAABoZKxcWsOF4AAAABYQmgAAACwgNAEAAFhAaAIAALCA0AQAAGABoQkAAMACQhMAAIAFhCYAAAALCE0AAAAWEJoAAAAsIDQBAABYQGgCAACwgNAEAABgAaEJAADAgkBfN4Brq3Pqpu+tOTo/4Rp0AgBA48KZJgAAAAsITQAAABYQmgAAACwgNAEAAFhAaAI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Onz4sMcxSktLlZiYKLvdrrCwMCUlJens2bMeNXv27NGgQYMUEhKiqKgopaene3UeAACgcbuiC8HHjx/v8fj+++/3ajPfdvr0ad1xxx0aPHiw3nnnHd144406fPiwWrdubdakp6dryZIlWrlypaKjozVnzhzFx8frs88+U0hIiCQpMTFRp06dUlZWlqqqqvTQQw9p4sSJWr16tSTJ7XZr6NChiouLU0ZGhvbu3auHH35YYWFhmjhxYoPOEQAANA42w48vTEpNTdWHH36o999//7LjhmHI6XRq2rRpeuKJJyRJ5eXlioiI0IoVKzR69GgdOHBAPXr00M6dO9W/f39JUmZmpoYPH64TJ07I6XRq6dKlmj17tlwul4KCgszX3rBhgw4ePGipV7fbLYfDofLyctntdi/M/sp1Tt3kk9f9V47OT/B1CwAAfKcref++qgvBG9qbb76p/v3765e//KXCw8PVp08f/fnPfzbHjxw5IpfLpbi4OHOfw+FQTEyMcnNzJUm5ubkKCwszA5MkxcXFKSAgQHl5eWbNnXfeaQYmSYqPj1dhYaFOnz592d4qKyvldrs9NgAA0HT5dWj64osvtHTpUnXp0kWbN2/Wo48+qscff1wrV66UJLlcLkmqc5+oiIgIc8zlcik8PNxjPDAwUG3atPGoudwxLn2Nb0tLS5PD4TC3qKioq5wtAADwZ34dmmpqatS3b18999xz6tOnjyZOnKgJEyYoIyPD161p1qxZKi8vN7fjx4/7uiUAANCA/Do0tW/fXj169PDY1717dxUVFUmSIiMjJUnFxcUeNcXFxeZYZGSkSkpKPMYvXLig0tJSj5rLHePS1/i24OBg2e12jw0AADRdfh2a7rjjDhUWFnrsO3TokDp16iRJio6OVmRkpLKzs81xt9utvLw8xcbGSpJiY2NVVlam/Px8s2bLli2qqalRTEyMWZOTk6OqqiqzJisrS127dvX4ph4AALh++XVomjJlij7++GM999xz+vzzz7V69WotW7ZMycnJki7eWHPy5Ml65pln9Oabb2rv3r0aN26cnE6nRowYIenimalhw4ZpwoQJ2rFjhz788EOlpKRo9OjRcjqdkqSxY8cqKChISUlJ2r9/v9auXavFix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mvrKzMCA4ONl577TXDMAzjs88+MyQZO3fuNGveeecdw2azGV9++WXDNd9AEhISjIcffthj38iRI43ExETDMK6vNfl2QPDW3F9++WWjdevWHv9mZs6caXTt2rWBZ3T1Lhckv23Hjh2GJOPYsWOGYTT9NWkIfDznB86fP6/8/HzFxcWZ+wICAhQXF6fc3FwfdnZtlJeXS5LatGkjScrPz1dVVZXHenTr1k0dO3Y01yM3N1e9evXyuPFofHy83G639u/ffw27957k5GQlJCR4zFu6PtfjzTffVP/+/fXLX/5S4eHh6tOnj/785z+b40eOHJHL5fJYE4fDoZiYGI81CQsLU//+/c2auLg4BQQEKC8v79pNxktuv/12ZWdn69ChQ5KkTz/9VB988IHuuusuSdfnmtTy1txzc3N15513KigoyKyJj49XYWGhTp8+fY1m03DKy8tls9nM30llTa4cdwT3A//4xz9UXV1d587jEREROnjwoI+6ujZqamo0efJk3XHHHerZs6ckyeVyKSgoqM4PIEdERMjlcpk1l1uv2rHGZs2aNfrkk0+0c+fOOmPX43p88cUXWrp0qaZOnarf/e532rlzpx5//HEFBQVp/Pjx5pwuN+dL1yQ8PNxjPDAwUG3atGmUa5Kamiq3261u3bqpWbNmqq6u1rPPPqvExERJui7XpJa35u5yuRQdHV3nGLVjrVu3bpD+r4Vz585p5syZGjNmjPkDvdf7mtQHoQk+lZycrH379umDDz7wdSs+c/z4cU2aNElZWVkKCQnxdTt+oaamRv3799dzzz0nSerTp4/27dunjIwMjR8/3sfd+cbrr7+uVatWafXq1frRj36kgoICTZ48WU6n87pdE1hTVVWlX/3qVzIMQ0uXLvV1O40aH8/5gXbt2qlZs2Z1vg1VXFysyMhIH3XV8FJSUrRx40Zt3bpVHTp0MPdHRkbq/PnzKisr86i/dD0iIyMvu161Y41Jfn6+SkpK1LdvXwUGBiowMFDbt2/XkiVLFBgYqIiIiOtqPSSpffv26tGjh8e+7t27q6ioSNL/zem7/s1ERkaqpKTEY/zChQsqLS1tlGsyffp0paamavTo0erVq5ceeOABTZkyRWlpaZKuzz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AAAAXBbXNAEAAFhAaAIAALCA0AQAAGABoQkAAMACQhMAAIAFhCYAAAALCE0AAAAWEJoAAAAsIDQBAABYQGgCAACwgNAEAABgAaEJAADAgv8Pem+l/EPbDp0AAAAASUVORK5CYII=",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "df[\"len_query\"].plot.hist(bins=50)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>query</th>\n",
       "      <th>id</th>\n",
       "      <th>answers</th>\n",
       "      <th>tools</th>\n",
       "      <th>n_tools</th>\n",
       "      <th>len_query</th>\n",
       "      <th>n_function_calls</th>\n",
       "      <th>n_turns</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>35918</th>\n",
       "      <td>You receive an email from an unknown sender wi...</td>\n",
       "      <td>35918</td>\n",
       "      <td>[{'name': 'chat_gpt_detector', 'arguments': {'...</td>\n",
       "      <td>[{'name': 'chat_gpt_detector', 'description': ...</td>\n",
       "      <td>1</td>\n",
       "      <td>312</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>49404</th>\n",
       "      <td>Can you conduct a t-test to determine if there...</td>\n",
       "      <td>49404</td>\n",
       "      <td>[{'name': 'independent_samples_t_test', 'argum...</td>\n",
       "      <td>[{'name': 'independent_samples_t_test', 'descr...</td>\n",
       "      <td>1</td>\n",
       "      <td>256</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>49154</th>\n",
       "      <td>A biologist is studying a bacterial culture wi...</td>\n",
       "      <td>49154</td>\n",
       "      <td>[{'name': 'bacterial_growth', 'arguments': {'i...</td>\n",
       "      <td>[{'name': 'bacterial_growth', 'description': '...</td>\n",
       "      <td>1</td>\n",
       "      <td>252</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>45209</th>\n",
       "      <td>Find popular tourist attractions within a 5000...</td>\n",
       "      <td>45209</td>\n",
       "      <td>[{'name': 'places_list_by_radius_nearby_search...</td>\n",
       "      <td>[{'name': 'places_list_by_radius_nearby_search...</td>\n",
       "      <td>1</td>\n",
       "      <td>233</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>41547</th>\n",
       "      <td>A list of numbers from 0 to 40 is given, but o...</td>\n",
       "      <td>41547</td>\n",
       "      <td>[{'name': 'find_missing_number', 'arguments': ...</td>\n",
       "      <td>[{'name': 'find_missing_number', 'description'...</td>\n",
       "      <td>1</td>\n",
       "      <td>263</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                                   query     id  \\\n",
       "35918  You receive an email from an unknown sender wi...  35918   \n",
       "49404  Can you conduct a t-test to determine if there...  49404   \n",
       "49154  A biologist is studying a bacterial culture wi...  49154   \n",
       "45209  Find popular tourist attractions within a 5000...  45209   \n",
       "41547  A list of numbers from 0 to 40 is given, but o...  41547   \n",
       "\n",
       "                                                 answers  \\\n",
       "35918  [{'name': 'chat_gpt_detector', 'arguments': {'...   \n",
       "49404  [{'name': 'independent_samples_t_test', 'argum...   \n",
       "49154  [{'name': 'bacterial_growth', 'arguments': {'i...   \n",
       "45209  [{'name': 'places_list_by_radius_nearby_search...   \n",
       "41547  [{'name': 'find_missing_number', 'arguments': ...   \n",
       "\n",
       "                                                   tools  n_tools  len_query  \\\n",
       "35918  [{'name': 'chat_gpt_detector', 'description': ...        1        312   \n",
       "49404  [{'name': 'independent_samples_t_test', 'descr...        1        256   \n",
       "49154  [{'name': 'bacterial_growth', 'description': '...        1        252   \n",
       "45209  [{'name': 'places_list_by_radius_nearby_search...        1        233   \n",
       "41547  [{'name': 'find_missing_number', 'description'...        1        263   \n",
       "\n",
       "       n_function_calls  n_turns  \n",
       "35918                 1        1  \n",
       "49404                 1        1  \n",
       "49154                 1        1  \n",
       "45209                 1        1  \n",
       "41547                 1        1  "
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "single_tool_single_call = df.query(\"len_query > 230 and n_tools == 1 and n_function_calls == 1\").sample(100, random_state=42)\n",
    "single_tool_single_call.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>query</th>\n",
       "      <th>id</th>\n",
       "      <th>answers</th>\n",
       "      <th>tools</th>\n",
       "      <th>n_tools</th>\n",
       "      <th>len_query</th>\n",
       "      <th>n_function_calls</th>\n",
       "      <th>n_turns</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>17443</th>\n",
       "      <td>Calculate the distance and time it takes to tr...</td>\n",
       "      <td>17443</td>\n",
       "      <td>[{'name': 'directions_between_2_locations', 'a...</td>\n",
       "      <td>[{'name': 'get_countries', 'description': 'Fet...</td>\n",
       "      <td>4</td>\n",
       "      <td>235</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>33976</th>\n",
       "      <td>I have an initial investment of $1000 and I ad...</td>\n",
       "      <td>33976</td>\n",
       "      <td>[{'name': 'project_investment_growth', 'argume...</td>\n",
       "      <td>[{'name': 'calculate_order_total', 'descriptio...</td>\n",
       "      <td>3</td>\n",
       "      <td>253</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>51943</th>\n",
       "      <td>I'm planning to invest $5,000, and I want to a...</td>\n",
       "      <td>51943</td>\n",
       "      <td>[{'name': 'project_investment_growth', 'argume...</td>\n",
       "      <td>[{'name': 'get_ip_zipcode', 'description': 'Re...</td>\n",
       "      <td>2</td>\n",
       "      <td>234</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24593</th>\n",
       "      <td>Verify if a Sudoku board with the following co...</td>\n",
       "      <td>24593</td>\n",
       "      <td>[{'name': 'is_valid_sudoku', 'arguments': {'bo...</td>\n",
       "      <td>[{'name': 'is_valid_sudoku', 'description': 'C...</td>\n",
       "      <td>3</td>\n",
       "      <td>492</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>37689</th>\n",
       "      <td>Calculate the total alimony one spouse would h...</td>\n",
       "      <td>37689</td>\n",
       "      <td>[{'name': 'california_alimony', 'arguments': {...</td>\n",
       "      <td>[{'name': 'is_valid_palindrome', 'description'...</td>\n",
       "      <td>5</td>\n",
       "      <td>241</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                                   query     id  \\\n",
       "17443  Calculate the distance and time it takes to tr...  17443   \n",
       "33976  I have an initial investment of $1000 and I ad...  33976   \n",
       "51943  I'm planning to invest $5,000, and I want to a...  51943   \n",
       "24593  Verify if a Sudoku board with the following co...  24593   \n",
       "37689  Calculate the total alimony one spouse would h...  37689   \n",
       "\n",
       "                                                 answers  \\\n",
       "17443  [{'name': 'directions_between_2_locations', 'a...   \n",
       "33976  [{'name': 'project_investment_growth', 'argume...   \n",
       "51943  [{'name': 'project_investment_growth', 'argume...   \n",
       "24593  [{'name': 'is_valid_sudoku', 'arguments': {'bo...   \n",
       "37689  [{'name': 'california_alimony', 'arguments': {...   \n",
       "\n",
       "                                                   tools  n_tools  len_query  \\\n",
       "17443  [{'name': 'get_countries', 'description': 'Fet...        4        235   \n",
       "33976  [{'name': 'calculate_order_total', 'descriptio...        3        253   \n",
       "51943  [{'name': 'get_ip_zipcode', 'description': 'Re...        2        234   \n",
       "24593  [{'name': 'is_valid_sudoku', 'description': 'C...        3        492   \n",
       "37689  [{'name': 'is_valid_palindrome', 'description'...        5        241   \n",
       "\n",
       "       n_function_calls  n_turns  \n",
       "17443                 1        1  \n",
       "33976                 1        1  \n",
       "51943                 1        1  \n",
       "24593                 1        1  \n",
       "37689                 1        1  "
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "multiple_tool_single_call = df.query(\"len_query > 230 and n_tools > 1 and n_function_calls == 1\").sample(100, random_state=42)\n",
    "multiple_tool_single_call.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>query</th>\n",
       "      <th>id</th>\n",
       "      <th>answers</th>\n",
       "      <th>tools</th>\n",
       "      <th>n_tools</th>\n",
       "      <th>len_query</th>\n",
       "      <th>n_function_calls</th>\n",
       "      <th>n_turns</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>8693</th>\n",
       "      <td>Could you fetch the English map tile for the l...</td>\n",
       "      <td>8693</td>\n",
       "      <td>[{'name': 'en_map_v1_z_x_y_png', 'arguments': ...</td>\n",
       "      <td>[{'name': 'en_map_v1_z_x_y_png', 'description'...</td>\n",
       "      <td>1</td>\n",
       "      <td>258</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>46580</th>\n",
       "      <td>I need the details of all Litecoin blocks mine...</td>\n",
       "      <td>46580</td>\n",
       "      <td>[{'name': 'get_litecoin_block_by_hash_or_heigh...</td>\n",
       "      <td>[{'name': 'get_litecoin_block_by_hash_or_heigh...</td>\n",
       "      <td>1</td>\n",
       "      <td>294</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12868</th>\n",
       "      <td>I need to find photos of three different busin...</td>\n",
       "      <td>12868</td>\n",
       "      <td>[{'name': 'business_photos', 'arguments': {'bu...</td>\n",
       "      <td>[{'name': 'business_photos', 'description': 'F...</td>\n",
       "      <td>1</td>\n",
       "      <td>323</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>44394</th>\n",
       "      <td>Calculate the recommended daily calorie intake...</td>\n",
       "      <td>44394</td>\n",
       "      <td>[{'name': 'calculate_calorie_intake', 'argumen...</td>\n",
       "      <td>[{'name': 'calculate_calorie_intake', 'descrip...</td>\n",
       "      <td>1</td>\n",
       "      <td>314</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>48976</th>\n",
       "      <td>Please search for a product on Tokopedia using...</td>\n",
       "      <td>48976</td>\n",
       "      <td>[{'name': 'search_product', 'arguments': {'que...</td>\n",
       "      <td>[{'name': 'search_product', 'description': 'Th...</td>\n",
       "      <td>1</td>\n",
       "      <td>320</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                                   query     id  \\\n",
       "8693   Could you fetch the English map tile for the l...   8693   \n",
       "46580  I need the details of all Litecoin blocks mine...  46580   \n",
       "12868  I need to find photos of three different busin...  12868   \n",
       "44394  Calculate the recommended daily calorie intake...  44394   \n",
       "48976  Please search for a product on Tokopedia using...  48976   \n",
       "\n",
       "                                                 answers  \\\n",
       "8693   [{'name': 'en_map_v1_z_x_y_png', 'arguments': ...   \n",
       "46580  [{'name': 'get_litecoin_block_by_hash_or_heigh...   \n",
       "12868  [{'name': 'business_photos', 'arguments': {'bu...   \n",
       "44394  [{'name': 'calculate_calorie_intake', 'argumen...   \n",
       "48976  [{'name': 'search_product', 'arguments': {'que...   \n",
       "\n",
       "                                                   tools  n_tools  len_query  \\\n",
       "8693   [{'name': 'en_map_v1_z_x_y_png', 'description'...        1        258   \n",
       "46580  [{'name': 'get_litecoin_block_by_hash_or_heigh...        1        294   \n",
       "12868  [{'name': 'business_photos', 'description': 'F...        1        323   \n",
       "44394  [{'name': 'calculate_calorie_intake', 'descrip...        1        314   \n",
       "48976  [{'name': 'search_product', 'description': 'Th...        1        320   \n",
       "\n",
       "       n_function_calls  n_turns  \n",
       "8693                  3        1  \n",
       "46580                 3        1  \n",
       "12868                 3        1  \n",
       "44394                 2        1  \n",
       "48976                 3        1  "
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "single_tool_multiple_call = df.query(\"len_query > 250 and n_tools == 1 and n_function_calls > 1\").sample(50, random_state=42)\n",
    "single_tool_multiple_call.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "n_function_calls\n",
       "2     25\n",
       "3     18\n",
       "4      3\n",
       "5      2\n",
       "7      1\n",
       "10     1\n",
       "Name: count, dtype: int64"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "single_tool_multiple_call.n_function_calls.value_counts()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "200\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>query</th>\n",
       "      <th>id</th>\n",
       "      <th>answers</th>\n",
       "      <th>tools</th>\n",
       "      <th>n_tools</th>\n",
       "      <th>len_query</th>\n",
       "      <th>n_function_calls</th>\n",
       "      <th>n_turns</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>9897</th>\n",
       "      <td>Could you please check the current stock price...</td>\n",
       "      <td>9897</td>\n",
       "      <td>[{'name': 'price_by_symbol', 'arguments': {'in...</td>\n",
       "      <td>[{'name': 'price_by_symbol', 'description': 'F...</td>\n",
       "      <td>2</td>\n",
       "      <td>140</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>38837</th>\n",
       "      <td>I want to know the return on investment for an...</td>\n",
       "      <td>38837</td>\n",
       "      <td>[{'name': 'calculate_investment_return', 'argu...</td>\n",
       "      <td>[{'name': 'calculate_investment_return', 'desc...</td>\n",
       "      <td>2</td>\n",
       "      <td>233</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>56946</th>\n",
       "      <td>Find out the car models produced by Honda. Sho...</td>\n",
       "      <td>56946</td>\n",
       "      <td>[{'name': 'get_car_models', 'arguments': {'mak...</td>\n",
       "      <td>[{'name': 'get_car_models', 'description': 'Fe...</td>\n",
       "      <td>2</td>\n",
       "      <td>106</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>57598</th>\n",
       "      <td>Who owns the domain 'example.com' and what is ...</td>\n",
       "      <td>57598</td>\n",
       "      <td>[{'name': 'whois', 'arguments': {'domain': 'ex...</td>\n",
       "      <td>[{'name': 'whois', 'description': 'Queries a W...</td>\n",
       "      <td>2</td>\n",
       "      <td>118</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>52753</th>\n",
       "      <td>I'm planning a trip to Tunisia and I want to v...</td>\n",
       "      <td>52753</td>\n",
       "      <td>[{'name': 'geocode', 'arguments': {'address': ...</td>\n",
       "      <td>[{'name': 'reverse_php', 'description': 'Perfo...</td>\n",
       "      <td>2</td>\n",
       "      <td>240</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                                   query     id  \\\n",
       "9897   Could you please check the current stock price...   9897   \n",
       "38837  I want to know the return on investment for an...  38837   \n",
       "56946  Find out the car models produced by Honda. Sho...  56946   \n",
       "57598  Who owns the domain 'example.com' and what is ...  57598   \n",
       "52753  I'm planning a trip to Tunisia and I want to v...  52753   \n",
       "\n",
       "                                                 answers  \\\n",
       "9897   [{'name': 'price_by_symbol', 'arguments': {'in...   \n",
       "38837  [{'name': 'calculate_investment_return', 'argu...   \n",
       "56946  [{'name': 'get_car_models', 'arguments': {'mak...   \n",
       "57598  [{'name': 'whois', 'arguments': {'domain': 'ex...   \n",
       "52753  [{'name': 'geocode', 'arguments': {'address': ...   \n",
       "\n",
       "                                                   tools  n_tools  len_query  \\\n",
       "9897   [{'name': 'price_by_symbol', 'description': 'F...        2        140   \n",
       "38837  [{'name': 'calculate_investment_return', 'desc...        2        233   \n",
       "56946  [{'name': 'get_car_models', 'description': 'Fe...        2        106   \n",
       "57598  [{'name': 'whois', 'description': 'Queries a W...        2        118   \n",
       "52753  [{'name': 'reverse_php', 'description': 'Perfo...        2        240   \n",
       "\n",
       "       n_function_calls  n_turns  \n",
       "9897                  2        1  \n",
       "38837                 2        1  \n",
       "56946                 2        1  \n",
       "57598                 2        1  \n",
       "52753                 2        1  "
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "total_rows = 200\n",
    "\n",
    "multiple_tool_multiple_call_long_query = df.query(\"len_query > 100 and n_tools > 1 and n_function_calls > 1\")\n",
    "\n",
    "# select 10 samples for each n_function_calls where 1<n_tools<8 and 1<n_function_calls<6\n",
    "n_answers_samples = []\n",
    "for i in range(2, 8):\n",
    "    temp = multiple_tool_multiple_call_long_query.query(f\"n_tools == {i}\")\n",
    "    if len(temp) > 20:\n",
    "        temp = temp.sample(20, random_state=42)\n",
    "    n_answers_samples.append(temp)\n",
    "    \n",
    "for i in range(2, 6):\n",
    "    temp = multiple_tool_multiple_call_long_query.query(f\"n_function_calls == {i}\")\n",
    "    if len(temp) > 20:\n",
    "        temp = temp.sample(20, random_state=42)\n",
    "    n_answers_samples.append(temp)\n",
    "    \n",
    "temp = pd.concat(n_answers_samples)\n",
    "temp = temp.drop_duplicates(\"query\")\n",
    "\n",
    "remaining = total_rows - len(temp)\n",
    "if remaining:\n",
    "    # select remaining samples randomly \n",
    "    multiple_tool_multiple_call = pd.concat([temp, multiple_tool_multiple_call_long_query.sample(remaining, random_state=42)])\n",
    "\n",
    "print(len(multiple_tool_multiple_call.drop_duplicates(\"query\")))\n",
    "multiple_tool_multiple_call.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(n_tools\n",
       " 4    45\n",
       " 3    44\n",
       " 2    40\n",
       " 5    24\n",
       " 6    22\n",
       " 7    22\n",
       " Name: count, dtype: int64,\n",
       " n_function_calls\n",
       " 2    121\n",
       " 3     33\n",
       " 4     22\n",
       " 5     21\n",
       " Name: count, dtype: int64)"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# get value counts on temp for n_answers and n_tools\n",
    "temp.n_tools.value_counts(), temp.n_function_calls.value_counts()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "# i = 2\n",
    "# test = temp[temp.n_function_calls == 5]\n",
    "# test[\"query\"].values[i], test.tools.values[i], test.answers.values[i]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "189\n",
      "200\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>query</th>\n",
       "      <th>id</th>\n",
       "      <th>answers</th>\n",
       "      <th>tools</th>\n",
       "      <th>n_tools</th>\n",
       "      <th>len_query</th>\n",
       "      <th>n_function_calls</th>\n",
       "      <th>n_turns</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>15695</th>\n",
       "      <td>I'm planning a trip to Japan and want to know ...</td>\n",
       "      <td>15695</td>\n",
       "      <td>[{'name': 'search', 'arguments': {'search': 'J...</td>\n",
       "      <td>[{'name': 'search', 'description': 'Searches b...</td>\n",
       "      <td>1</td>\n",
       "      <td>198</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9275</th>\n",
       "      <td>I'm interested in the LN of the low prices for...</td>\n",
       "      <td>9275</td>\n",
       "      <td>[{'name': 'ln', 'arguments': {'symbol': 'IXIC'...</td>\n",
       "      <td>[{'name': 'ln', 'description': 'Returns the na...</td>\n",
       "      <td>1</td>\n",
       "      <td>145</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>36813</th>\n",
       "      <td>I need to sort the numbers 1.1, 2.2, and 3.3, ...</td>\n",
       "      <td>36813</td>\n",
       "      <td>[{'name': 'sort_numbers', 'arguments': {'numbe...</td>\n",
       "      <td>[{'name': 'sort_numbers', 'description': 'Sort...</td>\n",
       "      <td>1</td>\n",
       "      <td>115</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>48546</th>\n",
       "      <td>Find potentially undervalued large cap stocks ...</td>\n",
       "      <td>48546</td>\n",
       "      <td>[{'name': 'market_undervalued_large_caps', 'ar...</td>\n",
       "      <td>[{'name': 'market_undervalued_large_caps', 'de...</td>\n",
       "      <td>1</td>\n",
       "      <td>104</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>47954</th>\n",
       "      <td>I'm designing a triangular sail for my boat, a...</td>\n",
       "      <td>47954</td>\n",
       "      <td>[{'name': 'triangle_area', 'arguments': {'base...</td>\n",
       "      <td>[{'name': 'triangle_area', 'description': 'Com...</td>\n",
       "      <td>1</td>\n",
       "      <td>167</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                                   query     id  \\\n",
       "15695  I'm planning a trip to Japan and want to know ...  15695   \n",
       "9275   I'm interested in the LN of the low prices for...   9275   \n",
       "36813  I need to sort the numbers 1.1, 2.2, and 3.3, ...  36813   \n",
       "48546  Find potentially undervalued large cap stocks ...  48546   \n",
       "47954  I'm designing a triangular sail for my boat, a...  47954   \n",
       "\n",
       "                                                 answers  \\\n",
       "15695  [{'name': 'search', 'arguments': {'search': 'J...   \n",
       "9275   [{'name': 'ln', 'arguments': {'symbol': 'IXIC'...   \n",
       "36813  [{'name': 'sort_numbers', 'arguments': {'numbe...   \n",
       "48546  [{'name': 'market_undervalued_large_caps', 'ar...   \n",
       "47954  [{'name': 'triangle_area', 'arguments': {'base...   \n",
       "\n",
       "                                                   tools  n_tools  len_query  \\\n",
       "15695  [{'name': 'search', 'description': 'Searches b...        1        198   \n",
       "9275   [{'name': 'ln', 'description': 'Returns the na...        1        145   \n",
       "36813  [{'name': 'sort_numbers', 'description': 'Sort...        1        115   \n",
       "48546  [{'name': 'market_undervalued_large_caps', 'de...        1        104   \n",
       "47954  [{'name': 'triangle_area', 'description': 'Com...        1        167   \n",
       "\n",
       "       n_function_calls  n_turns  \n",
       "15695                 2        1  \n",
       "9275                  1        1  \n",
       "36813                 2        1  \n",
       "48546                 3        1  \n",
       "47954                 1        1  "
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "total_rows = 200\n",
    "\n",
    "df_long_query = df.query(\"len_query > 100\")\n",
    "\n",
    "# select 10 samples for each n_function_calls where 1<n_tools<8 and 1<n_function_calls<6\n",
    "n_answers_samples = []\n",
    "for i in range(1, 8):\n",
    "    temp = df_long_query.query(f\"n_tools == {i}\")\n",
    "    if len(temp) > 20:\n",
    "        temp = temp.sample(20, random_state=0)\n",
    "    n_answers_samples.append(temp)\n",
    "    \n",
    "for i in range(1, 6):\n",
    "    temp = df_long_query.query(f\"n_function_calls == {i}\")\n",
    "    if len(temp) > 10:\n",
    "        temp = temp.sample(10, random_state=0)\n",
    "    n_answers_samples.append(temp)\n",
    "    \n",
    "temp = pd.concat(n_answers_samples)\n",
    "temp = temp.drop_duplicates(\"query\")\n",
    "\n",
    "print(len(temp))\n",
    "\n",
    "remaining = total_rows - len(temp)\n",
    "if remaining:\n",
    "    # select remaining samples randomly \n",
    "    tool_miss = pd.concat([temp, df_long_query.sample(remaining, random_state=0)])\n",
    "\n",
    "print(len(tool_miss.drop_duplicates(\"query\")))\n",
    "tool_miss.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(n_tools\n",
       " 4    41\n",
       " 1    32\n",
       " 3    29\n",
       " 2    28\n",
       " 5    25\n",
       " 6    22\n",
       " 7    22\n",
       " 8     1\n",
       " Name: count, dtype: int64,\n",
       " n_function_calls\n",
       " 2    94\n",
       " 1    43\n",
       " 3    35\n",
       " 4    17\n",
       " 5    10\n",
       " 9     1\n",
       " Name: count, dtype: int64)"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tool_miss.n_tools.value_counts(), tool_miss.n_function_calls.value_counts()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "  0%|          | 0/200 [00:00<?, ?it/s]"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "100%|██████████| 200/200 [00:00<00:00, 13406.54it/s]\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>query</th>\n",
       "      <th>id</th>\n",
       "      <th>answers</th>\n",
       "      <th>tools</th>\n",
       "      <th>n_tools</th>\n",
       "      <th>len_query</th>\n",
       "      <th>n_function_calls</th>\n",
       "      <th>n_turns</th>\n",
       "      <th>tool_removed</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>15737</th>\n",
       "      <td>Reverse the string 'Algorithm', calculate the ...</td>\n",
       "      <td>15737</td>\n",
       "      <td>[{'name': 'calculate_grade', 'arguments': {'sc...</td>\n",
       "      <td>[{'name': 'is_anagram', 'description': 'Checks...</td>\n",
       "      <td>5</td>\n",
       "      <td>149</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>{'name': 'reverse_string', 'arguments': {'text...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>53488</th>\n",
       "      <td>Search for financial stocks related to 'google...</td>\n",
       "      <td>53488</td>\n",
       "      <td>[{'name': 'get_2_stockdetails', 'arguments': {...</td>\n",
       "      <td>[{'name': 'get_2_stockdetails', 'description':...</td>\n",
       "      <td>2</td>\n",
       "      <td>116</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>{'name': 'search', 'arguments': {'query': 'goo...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20492</th>\n",
       "      <td>Fetch user information for email 'example@emai...</td>\n",
       "      <td>20492</td>\n",
       "      <td>[{'name': 'dashboard', 'arguments': {'login_id...</td>\n",
       "      <td>[{'name': 'getpetbyid', 'description': 'Get de...</td>\n",
       "      <td>6</td>\n",
       "      <td>149</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>{'name': 'getusers', 'arguments': {'email': 'e...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>55623</th>\n",
       "      <td>Get the live match data for match ID '6789' an...</td>\n",
       "      <td>55623</td>\n",
       "      <td>[{'name': 'summary', 'arguments': {'identifier...</td>\n",
       "      <td>[{'name': 'summary', 'description': 'Fetches t...</td>\n",
       "      <td>2</td>\n",
       "      <td>120</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>{'name': 'provider1_live_match_id', 'arguments...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>53985</th>\n",
       "      <td>I'd like to know the revenue estimate for Micr...</td>\n",
       "      <td>53985</td>\n",
       "      <td>[{'name': 'revenue_estimate', 'arguments': {'t...</td>\n",
       "      <td>[{'name': 'revenue_estimate', 'description': '...</td>\n",
       "      <td>3</td>\n",
       "      <td>221</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>{'name': 'time_series', 'arguments': {'symbol'...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                                   query     id  \\\n",
       "15737  Reverse the string 'Algorithm', calculate the ...  15737   \n",
       "53488  Search for financial stocks related to 'google...  53488   \n",
       "20492  Fetch user information for email 'example@emai...  20492   \n",
       "55623  Get the live match data for match ID '6789' an...  55623   \n",
       "53985  I'd like to know the revenue estimate for Micr...  53985   \n",
       "\n",
       "                                                 answers  \\\n",
       "15737  [{'name': 'calculate_grade', 'arguments': {'sc...   \n",
       "53488  [{'name': 'get_2_stockdetails', 'arguments': {...   \n",
       "20492  [{'name': 'dashboard', 'arguments': {'login_id...   \n",
       "55623  [{'name': 'summary', 'arguments': {'identifier...   \n",
       "53985  [{'name': 'revenue_estimate', 'arguments': {'t...   \n",
       "\n",
       "                                                   tools  n_tools  len_query  \\\n",
       "15737  [{'name': 'is_anagram', 'description': 'Checks...        5        149   \n",
       "53488  [{'name': 'get_2_stockdetails', 'description':...        2        116   \n",
       "20492  [{'name': 'getpetbyid', 'description': 'Get de...        6        149   \n",
       "55623  [{'name': 'summary', 'description': 'Fetches t...        2        120   \n",
       "53985  [{'name': 'revenue_estimate', 'description': '...        3        221   \n",
       "\n",
       "       n_function_calls  n_turns  \\\n",
       "15737                 2        1   \n",
       "53488                 1        1   \n",
       "20492                 1        1   \n",
       "55623                 1        1   \n",
       "53985                 3        1   \n",
       "\n",
       "                                            tool_removed  \n",
       "15737  {'name': 'reverse_string', 'arguments': {'text...  \n",
       "53488  {'name': 'search', 'arguments': {'query': 'goo...  \n",
       "20492  {'name': 'getusers', 'arguments': {'email': 'e...  \n",
       "55623  {'name': 'provider1_live_match_id', 'arguments...  \n",
       "53985  {'name': 'time_series', 'arguments': {'symbol'...  "
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\n",
    "\n",
    "# tools = [{'name': 'price_by_symbol',\n",
    "#   'description': 'Fetches the live price of a stock by its symbol.',\n",
    "#   'parameters': {'input': {'description': 'The stock symbol to query.',\n",
    "#     'type': 'str',\n",
    "#     'default': 'AAPL'}}},\n",
    "#  {'name': 'stock_earnings',\n",
    "#   'description': 'Retrieve earnings information for a particular stock symbol using the Yahoo Finance API.',\n",
    "#   'parameters': {'symbol': {'description': 'The stock symbol for which to retrieve earnings information.',\n",
    "#     'type': 'str',\n",
    "#     'default': 'AAPL'}}}]\n",
    "\n",
    "# answers =  [{'name': 'price_by_symbol', 'arguments': {'input': 'AAPL'}},\n",
    "#   {'name': 'stock_earnings', 'arguments': {'symbol': 'MSFT'}}])\n",
    "\n",
    "\n",
    "# write a func to do following steps for above tools and answers\n",
    "# 1. select random tool name from answers\n",
    "# 2. remove that tool from tools\n",
    "\n",
    "def remove_tools(tools, answers):\n",
    "    import random\n",
    "    tool_removed = random.choice(answers)\n",
    "    answers = [ans for ans in answers if ans[\"name\"] != tool_removed[\"name\"]]\n",
    "    tools = [t for t in tools if t[\"name\"] != tool_removed[\"name\"]]\n",
    "    return tools, answers, tool_removed\n",
    "\n",
    "# apply this func to col tools and answers of df\n",
    "tool_miss[\"tools\"], tool_miss[\"answers\"], tool_miss[\"tool_removed\"] = zip(*tool_miss.progress_apply(lambda x: remove_tools(x[\"tools\"], x[\"answers\"]), axis=1))\n",
    "tool_miss[\"n_tools\"] = tool_miss.tools.apply(lambda x: len(x))\n",
    "tool_miss = tool_miss[tool_miss.n_tools > 0].sample(100, random_state=42)\n",
    "tool_miss[\"n_function_calls\"] = tool_miss[\"answers\"].apply(lambda x: len(x))\n",
    "tool_miss.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>query</th>\n",
       "      <th>id</th>\n",
       "      <th>answers</th>\n",
       "      <th>tools</th>\n",
       "      <th>n_tools</th>\n",
       "      <th>len_query</th>\n",
       "      <th>n_function_calls</th>\n",
       "      <th>n_turns</th>\n",
       "      <th>tool_removed</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>39668</th>\n",
       "      <td>Calculate the quarterly dividend per share for...</td>\n",
       "      <td>39668</td>\n",
       "      <td>[{'name': 'least_common_multiple', 'arguments'...</td>\n",
       "      <td>[{'name': 'independent_samples_t_test', 'descr...</td>\n",
       "      <td>4</td>\n",
       "      <td>174</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>{'name': 'calculate_quarterly_dividend', 'argu...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>44488</th>\n",
       "      <td>Retrieve the cash flow statement for Tesla and...</td>\n",
       "      <td>44488</td>\n",
       "      <td>[{'name': 'stock_cashflow_statement', 'argumen...</td>\n",
       "      <td>[{'name': 'stock_cashflow_statement', 'descrip...</td>\n",
       "      <td>2</td>\n",
       "      <td>216</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>{'name': 'aroon', 'arguments': {'symbol': 'BTC...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28392</th>\n",
       "      <td>I need to find the 10th Fibonacci number, the ...</td>\n",
       "      <td>28392</td>\n",
       "      <td>[{'name': 'fibonacci', 'arguments': {'n': 10}}...</td>\n",
       "      <td>[{'name': 'fibonacci', 'description': 'Calcula...</td>\n",
       "      <td>6</td>\n",
       "      <td>250</td>\n",
       "      <td>4</td>\n",
       "      <td>1</td>\n",
       "      <td>{'name': 'find_max_subarray_sum', 'arguments':...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4748</th>\n",
       "      <td>A conference organizer has the following sched...</td>\n",
       "      <td>4748</td>\n",
       "      <td>[]</td>\n",
       "      <td>[{'name': 'displacement', 'description': 'Calc...</td>\n",
       "      <td>2</td>\n",
       "      <td>185</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>{'name': 'min_meeting_rooms', 'arguments': {'i...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23625</th>\n",
       "      <td>Compute the Euclidean distance between points ...</td>\n",
       "      <td>23625</td>\n",
       "      <td>[{'name': 'euclidean_distance', 'arguments': {...</td>\n",
       "      <td>[{'name': 'find_equilibrium_index', 'descripti...</td>\n",
       "      <td>2</td>\n",
       "      <td>212</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>{'name': 'neuronal_activity_rate', 'arguments'...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                                   query     id  \\\n",
       "39668  Calculate the quarterly dividend per share for...  39668   \n",
       "44488  Retrieve the cash flow statement for Tesla and...  44488   \n",
       "28392  I need to find the 10th Fibonacci number, the ...  28392   \n",
       "4748   A conference organizer has the following sched...   4748   \n",
       "23625  Compute the Euclidean distance between points ...  23625   \n",
       "\n",
       "                                                 answers  \\\n",
       "39668  [{'name': 'least_common_multiple', 'arguments'...   \n",
       "44488  [{'name': 'stock_cashflow_statement', 'argumen...   \n",
       "28392  [{'name': 'fibonacci', 'arguments': {'n': 10}}...   \n",
       "4748                                                  []   \n",
       "23625  [{'name': 'euclidean_distance', 'arguments': {...   \n",
       "\n",
       "                                                   tools  n_tools  len_query  \\\n",
       "39668  [{'name': 'independent_samples_t_test', 'descr...        4        174   \n",
       "44488  [{'name': 'stock_cashflow_statement', 'descrip...        2        216   \n",
       "28392  [{'name': 'fibonacci', 'description': 'Calcula...        6        250   \n",
       "4748   [{'name': 'displacement', 'description': 'Calc...        2        185   \n",
       "23625  [{'name': 'find_equilibrium_index', 'descripti...        2        212   \n",
       "\n",
       "       n_function_calls  n_turns  \\\n",
       "39668                 1        1   \n",
       "44488                 2        1   \n",
       "28392                 4        1   \n",
       "4748                  0        1   \n",
       "23625                 1        1   \n",
       "\n",
       "                                            tool_removed  \n",
       "39668  {'name': 'calculate_quarterly_dividend', 'argu...  \n",
       "44488  {'name': 'aroon', 'arguments': {'symbol': 'BTC...  \n",
       "28392  {'name': 'find_max_subarray_sum', 'arguments':...  \n",
       "4748   {'name': 'min_meeting_rooms', 'arguments': {'i...  \n",
       "23625  {'name': 'neuronal_activity_rate', 'arguments'...  "
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tool_miss.tail()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "xlam_single_tool_single_call (100, 9)\n",
      "xlam_multiple_tool_single_call (100, 9)\n",
      "xlam_single_tool_multiple_call (50, 9)\n",
      "xlam_multiple_tool_multiple_call (200, 9)\n",
      "xlam_tool_miss (100, 10)\n"
     ]
    }
   ],
   "source": [
    "def convert_tools_to_langchain_format(tools):\n",
    "    def convert_type(t):\n",
    "        type_mapping = {\n",
    "            \"float\": \"number\",\n",
    "            \"int\": \"integer\",\n",
    "            \"str\": \"string\",\n",
    "            \"bool\": \"boolean\",\n",
    "            \"dict\": \"object\",\n",
    "            \"list\": \"array\"\n",
    "        }\n",
    "        return type_mapping.get(t.lower() if isinstance(t, str) else t, \"string\")\n",
    "    \n",
    "    def convert_parameter(param_info):\n",
    "        prop = {\n",
    "            \"description\": param_info[\"description\"],\n",
    "            \"type\": convert_type(param_info[\"type\"])\n",
    "        }\n",
    "        \n",
    "        if prop[\"type\"] == \"array\":\n",
    "            # Default to string items if not specified\n",
    "            prop[\"items\"] = {\"type\": \"string\"}\n",
    "            \n",
    "            # If item type is specified in the description, try to infer it\n",
    "            desc_lower = param_info[\"description\"].lower()\n",
    "            if \"integer\" in desc_lower or \"number\" in desc_lower:\n",
    "                prop[\"items\"][\"type\"] = \"number\"\n",
    "            elif \"boolean\" in desc_lower:\n",
    "                prop[\"items\"][\"type\"] = \"boolean\"\n",
    "        \n",
    "        return prop\n",
    "\n",
    "    def convert_single_tool(tool):\n",
    "        properties = {}\n",
    "        required = []\n",
    "        \n",
    "        for param_name, param_info in tool[\"parameters\"].items():\n",
    "            prop = convert_parameter(param_info)\n",
    "            prop[\"title\"] = param_name.title()\n",
    "            \n",
    "            if \"default\" not in param_info:\n",
    "                required.append(param_name)\n",
    "                \n",
    "            properties[param_name] = prop\n",
    "\n",
    "        return {\n",
    "            \"description\": tool[\"description\"],\n",
    "            \"properties\": properties,\n",
    "            \"required\": required,\n",
    "            \"title\": tool[\"name\"],\n",
    "            \"type\": \"object\"\n",
    "        }\n",
    "\n",
    "    if isinstance(tools, list):\n",
    "        return [convert_single_tool(tool) for tool in tools]\n",
    "    elif isinstance(tools, dict):\n",
    "        return convert_single_tool(tools)\n",
    "    else:\n",
    "        raise ValueError(\"Input must be either a single tool dict or a list of tool dicts\")\n",
    "\n",
    "def remove_duplicate_tools(tools_langchain):\n",
    "    unique_tools = []\n",
    "    unique_tool_names = set()\n",
    "    for tool in tools_langchain:\n",
    "        if tool[\"title\"] not in unique_tool_names:\n",
    "            unique_tools.append(tool)\n",
    "            unique_tool_names.add(tool[\"title\"])\n",
    "    return unique_tools\n",
    "\n",
    "for temp, name in [\n",
    "                   (single_tool_single_call, \"xlam_single_tool_single_call\"),\n",
    "                   (multiple_tool_single_call, \"xlam_multiple_tool_single_call\"), \n",
    "                   (single_tool_multiple_call, \"xlam_single_tool_multiple_call\"),\n",
    "                   (multiple_tool_multiple_call, \"xlam_multiple_tool_multiple_call\"),\n",
    "                   (tool_miss, \"xlam_tool_miss\")]:\n",
    "    temp[\"tools_langchain\"] = temp[\"tools\"].apply(convert_tools_to_langchain_format)\n",
    "    temp = temp.rename(columns={\"query\": \"conversation\"})\n",
    "    temp[\"conversation\"] = temp[\"conversation\"].apply(lambda x: [{\"role\": \"user\", \"content\": x}])\n",
    "    temp[\"tools_langchain\"] = temp[\"tools_langchain\"].apply(remove_duplicate_tools)\n",
    "    print(name, temp.shape)\n",
    "    temp.to_parquet(f\"../data/datasets/{name}.parquet\", engine=\"fastparquet\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "langgraph",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
